const dayStep = 86400000;    // 一天

export const getDays = (startTime, endTime) => {
  let ret = [];

  let unixA = new Date(startTime).getTime()
  let unixB = new Date(endTime).getTime()

  for (; unixA <= unixB; unixA += dayStep) {
    ret.push(new Date(unixA));
  }

  return ret;
}

export const getRole = role => {
  switch (role) {
    case 'student': return '学生';
    case 'teacher': return '教师';
    case 'base_manager': return '基地管理员';
    case 'admin': return '管理员';
  }
  return '';
}

export const getSignType = type => {
  switch (type) {
    case 'sign_in': return '签到';
    case 'sign_out': return '签退';
  }
  return '';
}

export const getSignStatus = status => {
  switch (status) {
    case 'not_signed_in': return '未签';
    case 'check_in': return '已签';
    case 'absent': return '缺勤';
    case 'patch': return '补签';
  }
  return '';
}

function toYMD_HMS (date) {
  if ( date ) {
    // date = new Date(date);
    // let month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : '0' + (date.getMonth() + 1);
    // let day = (date.getDate() > 9) ? (date.getDate()) : '0' + (date.getDate());
    // let hours = date.getHours() > 9 ? (date.getHours()) : '0' + date.getHours();
    // let minutes = date.getMinutes() > 9 ? date.getHours() : '0' + date.getHours();
    // let second = date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds();
    // return `${date.getFullYear()}-${month}-${day} ${hours}:${minutes}:${second}`; //1022-12-21 21:21
    return date ? date.replace('T', ' ').substring(0, 16) : '';
  }
  return '';
}

export const toYMD = date => {
  // let tmp;
  // return (tmp = toYMD_HMS(date)) ? tmp.substring(0, 10) : '';
  // console.log(date);
  // console.log(date)
  return date ? date.substring(0, 10) : '';
}

export const toYMD_HM = date => {
  // let tmp;
  // return (tmp = toYMD_HMS(date)) ? tmp.substring(0, 16) : '';
  return date ? date.replace('T', ' ').substring(0, 16) : '';
}

export const getReservationStatus = status => {
  switch (status) {
    case 'unfinished': return '未完成';
    case 'completed': return '已完成';
    case 'cancelled': return '已取消';
  }
  return '';
}

const menus = {
  '111':'资讯管理',
  '112':'基地管理',
  '113':'轮播图管理',
  '114':'留言管理',
  '115':'管理员管理',
  '116':'学校统计',
  '117':'基地统计',
  '118':'模块统计',
  '119':'日志管理'
}

export const getMenuName = id => {
    return menus[id];
}